//
//  KRAlbumListCell.m
//  cookBook
//
//  Created by kuroken on 16/1/14.
//  Copyright © 2016年 kuroken. All rights reserved.
//

#import "KRAlbumListCell.h"
#import "KRAlbumList.h"
#import <UIImageView+WebCache.h>
#import "KRConst.h"

// cell的标识
static NSString * const reuseIdentifier = @"albumList";

@interface KRAlbumListCell ()
@property (nonatomic, weak) UILabel *collectionLabel;
@end

@implementation KRAlbumListCell

+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    KRAlbumListCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
    if (cell == nil) {
        cell = [[KRAlbumListCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuseIdentifier];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // 添加收藏/浏览label
        UILabel *collectionLabel = [[UILabel alloc] init];
        [self.contentView addSubview:collectionLabel];
        self.collectionLabel = collectionLabel;

        self.textLabel.font = [UIFont systemFontOfSize:15];
        self.collectionLabel.font = [UIFont systemFontOfSize:13];
        self.collectionLabel.textColor = [UIColor lightGrayColor];
        self.detailTextLabel.font = [UIFont systemFontOfSize:13];
        self.detailTextLabel.textColor = [UIColor lightGrayColor];
        
    }
    return self;
}

- (void)setAlbumList:(KRAlbumList *)albumList
{
    _albumList = albumList;
    
    [self.imageView sd_setImageWithURL:[NSURL URLWithString:albumList.cover] placeholderImage:[UIImage imageNamed:@"default_r172-118"]];
    [self.textLabel setText:albumList.title];
    [self.collectionLabel setText:albumList.collection];
    [self.detailTextLabel setText:albumList.content];

}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    // imageView.frame
    CGFloat imageX = 10;
    CGFloat imageY = 5 + cellPadding;  //顶部加10的间距   15
    CGFloat imageW = 100;
    CGFloat imageH = baseCellHeight + cellPadding * 2 - imageY * 2;
    self.imageView.frame = CGRectMake(imageX, imageY, imageW, imageH);
        
    // textLabel.frame
    CGFloat textX = CGRectGetMaxX(self.imageView.frame) + 15;
    CGFloat textY = imageY;
    CGFloat textW = KRAlbumListWidth - textX - 25;
    CGFloat textH = 22;
    self.textLabel.frame = CGRectMake(textX, textY, textW, textH);
    
    // collection.frame
    CGFloat collectionX = textX;
    CGFloat collectionY = CGRectGetMaxY(self.textLabel.frame) + 5;
    CGFloat collectionW = textW;
    CGFloat collectionH = 20;
    self.collectionLabel.frame = CGRectMake(collectionX, collectionY, collectionW, collectionH);
    
    // detailTextLabel.origin
    CGFloat detailX = textX;
    CGFloat detailY = CGRectGetMaxY(self.imageView.frame) - self.detailTextLabel.size.height;
    self.detailTextLabel.width = KRAlbumListWidth - detailX - 25;
    self.detailTextLabel.origin = CGPointMake(detailX, detailY);
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];


}

@end
